package com.barks.learning.base.config;

import com.barks.learning.base.intercepter.HandlerResult;
import com.barks.learning.base.intercepter.CustomIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author chenw-i
 * @version 1.0.0
 * @ClassName CustomConfig.java
 * @Description TODO
 * @createTime 2020年07月11日 18:58:00
 */
@Configuration
public class CustomConfig  implements WebMvcConfigurer {
    @Autowired
    CustomIntercepter intercepter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(intercepter);
    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
        // 好像这么加没有效果 ，可以使用 #WebMvcConfigurationSupport 这个可以
        HandlerResult handlerResult = new HandlerResult();
        handlers.add(handlerResult);
    }
}
